﻿using Microsoft.EntityFrameworkCore;
using Model;
using System;
using System.Collections.Generic;
using System.Text;

namespace Model
{
    public class SqlTechnological : ITechnological
    {
        private readonly AppDbContext appDbContext;
        public SqlTechnological(AppDbContext app)
        {
            this.appDbContext = app;
        }
        //添加请假申请
        public int AddLeaves(Leave l)
        {
            appDbContext.Leaves.Add(l);
            return appDbContext.SaveChanges();
        }

        //申请状态
        public IEnumerable<Astate> Astates()
        {
            return appDbContext.Astates;
        }
        public IEnumerable<Leave_type> leave_Types()
        {
            return appDbContext.leave_Types;
        }
        //请假申请待办查询
        public IEnumerable<Leave> Leaves()
        {
            return appDbContext.Leaves.Include(a=>a.Position).Include(a=>a.Astate).Include(a=>a.Position.Department).Include(a=>a.Leave_Type);
        }
        //加班申请待办查询
        public IEnumerable<work> Works()
        {
            return appDbContext.Works.Include(a => a.Position).Include(a => a.Astate).Include(a => a.Position.Department);
        }
        //加班申请添加
        public int AddWork(work w)
        {
            appDbContext.Works.Add(w);
            return appDbContext.SaveChanges();
        }
        //加班申请审核
        public int examineWork(work w)
        {
            var wo = appDbContext.Works.Find(w.WID);
            wo.Aid = 2;
            appDbContext.Works.Update(wo);
            return appDbContext.SaveChanges();
        }
        //请假审核
        public int examine(Leave l)
        {
            var le = appDbContext.Leaves.Find(l.LeaveID);
            le.Aid = 2;
            appDbContext.Leaves.Update(le);
            return appDbContext.SaveChanges();
        }
        //出差申请添加
        public int AddTravel(Travel t)
        {
            appDbContext.Travels.Add(t);
            return appDbContext.SaveChanges();
        }
        //出差待办查询
        public IEnumerable<Travel> Travels()
        {
            IEnumerable<Travel> list = appDbContext.Travels.Include(a => a.Position).Include(a => a.Astate).Include(a => a.Position.Department);
            return list;
        }

        //出差审核
        public int examineTravels(Travel t)
        {
            var tr = appDbContext.Travels.Find(t.id);
            tr.Aid = 2;
            appDbContext.Travels.Update(tr);
            return appDbContext.SaveChanges();
        }

        //添加活动申请
        public int AddActivity(Activity a)
        {
            appDbContext.Activities.Add(a);
            return appDbContext.SaveChanges();
        }
        //活动待办查询
        public IEnumerable<Activity> Activities()
        {
            IEnumerable<Activity> list = appDbContext.Activities.Include(a => a.Position).Include(a => a.Astate).Include(a => a.Position.Department);
            return list;
        }
    }
}
